package com.twu.biblioteca;

public class ReserveBook extends MenuOption {

    private BookShelf bookShelf;

    public ReserveBook(String name, BookShelf bookShelf) {
        super(name);
        this.bookShelf = bookShelf;
    }

    @Override
    protected String menuOptionHeader() {
        return "BOOK LIST\n___________________________________ \nISBN\t\tBOOK TITLE\t\tAUTHOR\n";
    }

    @Override
    protected String menuOptionBody() {
        return bookShelf.getBookList();
    }

    @Override
    protected String menuOptionFooter() {
        return "Please enter the book ISBN number\n";
    }

    @Override
    public String getResponse() {
        return String.format("%s %s %s", menuOptionHeader(), menuOptionBody(), menuOptionFooter());  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    protected boolean hasSubMenu() {
        return true;
    }

    @Override
    public String getSubMenuResponse(int ISBN) {
        return reservedBookForCollection(ISBN) ? "Thank You! Enjoy the book.\n" : "Sorry we don't have that book yet.\n";
    }

    private boolean reservedBookForCollection(int ISBN) {
        if(bookShelf.hasBookWith(ISBN)){
            Book book = bookShelf.getBookWithISBN(ISBN);
            if(!book.isBookReserved()) { book.reserveBook(); return true;}
        }
        return false;
    }




}
